home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
filutil
/
ygrep401.zip
/
DOS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-03
|
5KB
|
154 lines
#if !defined( lint )
static char *sccsid = "@(#)dos.c (C) Yves Roumazeilles 95/02/03";
#endif
#pragma warning(disable:4001)
/*
// Test program for DOS libs
//
// Just compile it with the appropriate model (corresponding to the one
// used by the library you selected:
// SYGREP.LIB (Microsoft) and SYGREPB.LIB (Borland) are Small model;
// CYGREP.LIB (Microsoft) and CYGREPB.LIB (Borland) are Compact model;
// MYGREP.LIB (Microsoft) and MYGREPB.LIB (Borland) are Medium model;
// LYGREP.LIB (Microsoft) and LYGREPB.LIB (Borland) are Large model;
// HYGREP.LIB (Microsoft) is Huge model.
//
// Version 2.0
*/
#define STRICT
#include <windows2.h>
#include <stdio.h>
#include <malloc.h>
#include "ygrep.h"
#define CHECK(a,b,s) if((a)!=(b)) {fprintf(stderr,"\n---"s"->(%d)\n",(a));return(-1);} else{fprintf(stderr,".");}
LPCSTR test[] = {
/*0*/ "include",
/*1*/ "includi",
/*2*/ "includeINCLUDE",
/*3*/ "toto",
/*4*/ "tototo",
/*5*/ "totototo",
/* */ "" };
main()
{
int iVal;
/* AGREPINFO aGI; */
LPAGREPINFO pGI;
LPRGREPINFO pRGI;
char* pTemp;
char* pSubs = "012345678901234567890123456789";
char* pDest = "012345678901234567890123456789";
printf("*** YGrep Search Engine diags level 1 ***\n\n");
printf("YGrepVersion: 0x%04x\n", YGrepVersion());
printf("Starting!\n");
pGI = (LPAGREPINFO)calloc(1, sizeof(AGREPINFO));
/* pGI = &aGI; */
CHECK( AGrepInit(pGI), TRUE, "init" );
// k=0 mismatch...
CHECK( CompileAGrep((LPCSTR)test[1], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp0" );
// ...0 matche(s)
CHECK( AGrep((LPCSTR)test[2], pGI), 0, "ag0" );
CHECK( AGrepEmpty(pGI), TRUE, "emp" );
// k=1 mismatch...
CHECK( CompileAGrep((LPCSTR)test[1], 1, TRUE, pGI), AGERR_NO_ERROR, "cmp1" );
// ...1 matche(s)
CHECK( AGrep((LPCSTR)test[2], pGI), 1, "ag1" );
CHECK( AGrepEmpty(pGI), TRUE, "emp" );
// k=1 mismatch, but no case...
CHECK( CompileAGrep((LPCSTR)test[1], 1, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
// ...2 matche(s)
CHECK( AGrep((LPCSTR)test[2], pGI), 2, "ag2" );
CHECK( AGrepSubsBuild("-&-", pSubs, 30, pGI), AGERR_NO_ERROR, "su0" );
CHECK( strcmp(pSubs,"-include-"), 0, "su1" );
CHECK( AGrepEmpty(pGI), TRUE, "emp" );
// ElectUnltd bug?
CHECK( CompileAGrep((LPCSTR)"Bob", 5, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
//fprintf( stderr, "%3d", AGrep((LPCSTR)"Ben", pGI) );
//fprintf( stderr, "%3d", AGrep((LPCSTR)test[2], pGI) );
//fprintf( stderr, "%3d", AGrep((LPCSTR)"Ben τa alors, tiens !", pGI) );
CHECK( AGrep((LPCSTR)"Ben", pGI), 3, "eu1" );
CHECK( AGrep((LPCSTR)test[2], pGI), 14, "eu2" );
CHECK( AGrep((LPCSTR)"Ben τa alors, tiens !", pGI), 21, "eu3" );
#define LONGUEUR 2300
pTemp = (char*)calloc(LONGUEUR,sizeof(char));
if( pTemp==NULL )
fprintf(stderr, "!");
else {
for( iVal=0; iVal<LONGUEUR-1; iVal++ )
pTemp[iVal] = '!';
pTemp[LONGUEUR-1]='\0';
/*fprintf(stderr,"*");*/
CHECK( AGrep((LPCSTR)pTemp, pGI), (int)strlen(pTemp), "eu4" );
}
CHECK( AGrepEmpty(pGI), TRUE, "emp" );
CHECK( CompileAGrep((LPCSTR)"Bob", 1, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
CHECK( AGrep((LPCSTR)pTemp, pGI), 0, "eu5" );
CHECK( AGrepEmpty(pGI), TRUE, "emp" );
free(pTemp);
// January bug check
CHECK( CompileAGrep((LPCSTR)test[3], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp3" );
CHECK( AGrep((LPCSTR)test[4], pGI), 2, "to1" );
CHECK( AGrep((LPCSTR)test[5], pGI), 3, "to2" );
CHECK( AGrepEmpty(pGI), TRUE, "emp" );
CHECK( CompileAGrep((LPCSTR)test[4], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp4" );
CHECK( AGrep((LPCSTR)test[5], pGI), 2, "to3" );
CHECK( AGrepEmpty(pGI), TRUE, "emp" );
free(pGI);
pRGI = (LPRGREPINFO)calloc(1, sizeof(RGREPINFO));
free(pRGI);
printf("\nEnding!\n");
return 0;
}
/*
// Some comments. Without any order...
*/
/*
// Nobody ever reads what is in the sample source code. However, you
// will be able to know why there is no AGREPINFO variable built in
// an automatic variable inside main(). It would have been nice and
// simpler than allocating it from the heap with calloc(). Well...
// Yes but there is quite a problem with large data structures like
// this one when they are built from the stack. E.g. with Borland C++
// v4.0, you would have to increase manually the stack for the simplest
// program - like this one - to operate smoothly.
// In the original version, I was building an AGREPINFO aGI variable
// as an automatic variable (it may still be present as a code comment),
// but this had a too large impact on code and data size for some of the
// memory models. See below.
*/
/*
// You must also remember that the YGrep Search Engine is a rather large
// set of routines and data. For real world applications it is highly
// improbable that you will be able to use the Small or Compact memory
// models. The data segment is too small for that.
// This size limitation can also appear when compiling applications with
// full debug information. E.g. Borland C++ 4.0 insisted on producing a
// stack overflow on entering main() [before reaching the first C code
// line.]
*/